from flask import Flask, render_template, request
from datetime import datetime

from user import User

app = Flask(__name__)


def my_date_format(value, pattern="%Y-%m-%d %H:%M:%S"):
    return value.strftime(pattern)


app.add_template_filter(my_date_format, "df")


@app.route("/login")
def login():
    return render_template("login.html")


@app.route("/")
def first_page():
    user = User("yujikuan", 28, "郑州高新区", "3229656576@qq.com")
    print(f"user={user}")
    print(user.username)

    mydict = {"title": "我的标题", "content": "我的内容"}
    print("title", mydict['title'], mydict.get('title'))
    cur_time = datetime.now()
    age = request.args.get("age", 18, type=int)

    user_list = []
    user_list.append(user)
    user_list.append(User('zhangsan', 15, '开封杞县', mail="demo@qq.com"))

    return render_template("first_page.html", user_list=user_list, age=age, cur_time=cur_time, user=user, mydict=mydict,
                           title="我的首页",
                           username="yujikuan")


if __name__ == '__main__':
    app.run("0.0.0.0", 5000, debug=True)
